import axios from 'axios';

// 换为自己的 API Key
const API_KEY = 'sk-6a7c1baad3d14d70a86cfaca54166c46';
const API_URL = 'https://api.deepseek.com/chat/completions';

export const fetchAIAsswer = async (question) => {
  try {
    const response = await axios.post(API_URL, {
      // 根据 DeepSeek API 要求的参数格式传递
      model: 'deepseek-chat', // 模型名称，可根据需求换
      messages: [
        {
          role: 'user',
          content: question,
        },
      ],
      max_tokens: 1000,
    }, {
      headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${API_KEY}`, // 携带 API Key 认证
      },
    });
    return response.data.choices[0].message.content; // 提取答案内容
  } catch (error) {
    console.error('调用 DeepSeek API 失败：', error);
    throw new Error('获取答案失败，请稍后再试');
  }
};
    